home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / SK (Sockects) 1.4.1 r2 / SK v1.4.1 r2.sit / SK 1.4.1 r2 / SK / SK Sources / SK_Socket.cc < prev    next >
Text File  |  1994-06-13  |  13KB  |  776 lines

  1. /***************************************************************************
  2. * Copyright ⌐ 1992-1994 Matthias Neeracher and the Decision Systems Group
  3. * Permission is granted to anyone to use this software for any purpose on
  4. * any computer system, and to redistribute it freely, subject to the
  5. * following restrictions:
  6. * 1) The authors and the Decision Systems Group are not responsible for 
  7. *    the direct or indirect consequences of use of this software, no matter 
  8. *    how awful, even if they arise from defects in the software itself.
  9. *    This restriction applies to the use of this and any derived source code 
  10. *    and also to the use of all binary produced from this and any derived 
  11. *    source code.
  12. * 2) The origin and copyrights of this software must not be misrepresented, 
  13. *    either by explicit claim or by omission or alteration of copyright or
  14. *    authorship header information in this file or in any derived file.
  15. * 3) Altered or derived versions must be plainly marked as such, and must not
  16. *    be misrepresented as being the original software.
  17. * We encourage users of this software to provide feedback, bug fixes,
  18. * and enhancements to the authors for incorporation into future releases.
  19. *
  20. * ==========================================================================
  21. * FILE: SK_INET.cc
  22. * AUTHOR: Matthias Neeracher and Stephan Deibel
  23. * CREATION DATE: 24Mar92
  24. * VERSION: 13Jun94
  25. * DESCRIPTION: 
  26. *
  27. * Default implementations for the socket generic class
  28. * NOTES: 
  29. * 0) This code was derived from Matthias Neerarcher's GUSI 1.1.0; Copyrights
  30. *    are subject to this origin.
  31. *
  32. * MODIFICATIONS: 
  33. * --------------------------------------------------------------------------
  34. * Date     Name      Description of modification
  35. * --------------------------------------------------------------------------
  36. * 27Apr92    MN       getsockopt()
  37. * 21May92    MN       Implement select()
  38. * 15Sep92    MN       Sockets are regular files for fstat()
  39. * 09Feb93    MN       Initialize fLurking related fields.
  40. * 13Jul93    SD       Port to THINK C++ 6.0
  41. * 21Jul93    SD       Subsetted to only TCP/UDP, applied DSG naming 
  42. *                    conventions and commenting guidelines, and
  43. *                    changed name to "SK" for clear distinction from
  44. *                    the GUSI code from which this was derived
  45. * 13Jun94   SD       Updated based on relevant changes to GUSI (through 1.4.1)
  46. */
  47.  
  48. #include "SK_P.hh"
  49.  
  50.  
  51. /*************************************************************************** *
  52. * FUNCTION:
  53. *
  54. * CSK_Socket::CSK_Socket
  55. *
  56. * DESCRIPTION:
  57. *
  58. * Constructor for this class
  59. *
  60. */
  61.  
  62. CSK_Socket::CSK_Socket()
  63. {
  64.     fRefCount    =    0;
  65.     fLurking    =    false;
  66.     fLurkDescr=    0;
  67. }
  68.  
  69.  
  70. /*************************************************************************** *
  71. * FUNCTION:
  72. *
  73. * CSK_Socket::~CSK_Socket
  74. *
  75. * DESCRIPTION:
  76. *
  77. * Destructor for this class
  78. *
  79. */
  80.  
  81. CSK_Socket::~CSK_Socket()
  82. {
  83. }
  84.  
  85.  
  86. /*************************************************************************** *
  87. * FUNCTION:
  88. *
  89. * CSK_Socket::bind
  90. *
  91. * DESCRIPTION:
  92. *
  93. * Bind this socket to the given entity
  94. *
  95. * PARAMETERS:
  96. *
  97. * void *        -- unused
  98. * int            -- unused
  99. *
  100. * RETURNS:
  101. *
  102. * int            -- Error value (0 = no error)
  103. *
  104. * NOTES:
  105. *
  106. * This should be implemented by descendents
  107. *
  108. */
  109.  
  110. int CSK_Socket::bind(void *, int)
  111. {
  112.     UNIMPLEMENTED;
  113.     return EOPNOTSUPP;
  114. }
  115.  
  116.  
  117. /*************************************************************************** *
  118. * FUNCTION:
  119. *
  120. * CSK_Socket::connect
  121. *
  122. * DESCRIPTION:
  123. *
  124. * Connect this socket to the given entity
  125. *
  126. * PARAMETERS:
  127. *
  128. * void *        -- unused
  129. * int            -- unused
  130. *
  131. * RETURNS:
  132. *
  133. * int            -- Error value (0 = no error)
  134. *
  135. * NOTES:
  136. *
  137. * This should be implemented by descendents
  138. *
  139. */
  140.  
  141. int CSK_Socket::connect(void *, int)
  142. {
  143.     UNIMPLEMENTED;
  144.     return EOPNOTSUPP;
  145. }
  146.  
  147.  
  148. /*************************************************************************** *
  149. * FUNCTION:
  150. *
  151. * CSK_Socket::listen
  152. *
  153. * DESCRIPTION:
  154. *
  155. * Listen for connections on this socket
  156. *
  157. * PARAMETERS:
  158. *
  159. * int            -- unused
  160. *
  161. * RETURNS:
  162. *
  163. * int            -- Error value (0 = no error)
  164. *
  165. * NOTES:
  166. *
  167. * This should be implemented by descendents
  168. *
  169. */
  170.  
  171. int CSK_Socket::listen(int)
  172. {
  173.     UNIMPLEMENTED;
  174.     return EOPNOTSUPP;
  175. }
  176.  
  177.  
  178. /*************************************************************************** *
  179. * FUNCTION:
  180. *
  181. * CSK_Socket::accept
  182. *
  183. * DESCRIPTION:
  184. *
  185. * Accept a connection on this socket
  186. *
  187. * PARAMETERS:
  188. *
  189. * void *        -- unused
  190. * int            -- unused
  191. *
  192. * RETURNS:
  193. *
  194. * CSK_Socket *    -- Newly created socket that will handle the new connection
  195. *                   (old socket continues to listen for additional connections)
  196. *
  197. * NOTES:
  198. *
  199. * This should be implemented by descendents
  200. *
  201. */
  202.  
  203. CSK_Socket * CSK_Socket::accept(void *, int *)
  204. {
  205.     return (CSK_Socket *) SK_Error_nil(EOPNOTSUPP);
  206. }
  207.  
  208.  
  209. /*************************************************************************** *
  210. * FUNCTION:
  211. *
  212. * CSK_Socket::read
  213. *
  214. * DESCRIPTION:
  215. *
  216. * Read bytes from this socket
  217. *
  218. * PARAMETERS:
  219. *
  220. * void *        -- Pointer to buffer for returned bytes
  221. * int            -- Length of given return buffer / number of bytes to read
  222. *
  223. * RETURNS:
  224. *
  225. * int            -- Number of bytes actually read (or 0 if none)
  226. *
  227. */
  228.  
  229. int CSK_Socket::read(void * buffer, int buflen)
  230. {
  231.     int    fromlen = 0;
  232.     
  233.     return recvfrom(buffer, buflen, 0, nil, &fromlen);
  234. }
  235.  
  236.  
  237. /*************************************************************************** *
  238. * FUNCTION:
  239. *
  240. * CSK_Socket::write
  241. *
  242. * DESCRIPTION:
  243. *
  244. * Write bytes to this socket
  245. *
  246. * PARAMETERS:
  247. *
  248. * void *        -- Pointer to buffer for bytes to write
  249. * int            -- Length of given buffer / number of bytes to write
  250. *
  251. * RETURNS:
  252. *
  253. * int            -- Number of bytes actually written (or 0 if none)
  254. *
  255. */
  256.  
  257. int CSK_Socket::write(void * buffer, int buflen)
  258. {
  259.     return sendto(buffer, buflen, 0, nil, 0);
  260. }
  261.  
  262.  
  263. /*************************************************************************** *
  264. * FUNCTION:
  265. *
  266. * CSK_Socket::recvfrom
  267. *
  268. * DESCRIPTION:
  269. *
  270. * Receive bytes from a given entity
  271. *
  272. * PARAMETERS:
  273. *
  274. * void *        -- unused
  275. * int            -- unused
  276. * int            -- unused
  277. * void *        -- unused
  278. * int *            -- unused
  279. *
  280. * RETURNS:
  281. *
  282. * int            -- Error value (0 = no error)
  283. *
  284. * NOTES:
  285. * This should be implemented by descendents
  286. */
  287.  
  288. int CSK_Socket::recvfrom(void *, int, int, void *, int *)
  289. {
  290.     UNIMPLEMENTED;
  291.     return EOPNOTSUPP;
  292. }
  293.  
  294.  
  295. /*************************************************************************** *
  296. * FUNCTION:
  297. *
  298. * CSK_Socket::sendto
  299. *
  300. * DESCRIPTION:
  301. *
  302. * Send bytes to a given entity
  303. *
  304. * PARAMETERS:
  305. *
  306. * void *        -- unused
  307. * int            -- unused
  308. * int            -- unused
  309. * void *        -- unused
  310. * int *            -- unused
  311. *
  312. * RETURNS:
  313. *
  314. * int            -- Error value (0 = no error)
  315. *
  316. * NOTES:
  317. * This should be implemented by descendents
  318. */
  319.  
  320. int CSK_Socket::sendto(void *, int, int, void *, int)
  321. {
  322.     UNIMPLEMENTED;
  323.     return EOPNOTSUPP;
  324. }
  325.  
  326.  
  327. /*************************************************************************** *
  328. * FUNCTION:
  329. *
  330. * CSK_Socket::getsockname
  331. *
  332. * DESCRIPTION:
  333. *
  334. * Get current name of this socket
  335. *
  336. * PARAMETERS:
  337. *
  338. * void *        -- unused
  339. * int *            -- unused
  340. *
  341. * RETURNS:
  342. *
  343. * int            -- Error value (0 = no error)
  344. *
  345. * NOTES:
  346. * This should be implemented by descendents
  347. */
  348.  
  349. int CSK_Socket::getsockname(void *, int *)
  350. {
  351.     UNIMPLEMENTED;
  352.     return EOPNOTSUPP;
  353. }
  354.  
  355.  
  356. /*************************************************************************** *
  357. * FUNCTION:
  358. *
  359. * CSK_Socket::getpeername
  360. *
  361. * DESCRIPTION:
  362. *
  363. * Get name of (remote) peer attached to this socket
  364. *
  365. * PARAMETERS:
  366. *
  367. * void *        -- unused
  368. * int *            -- unused
  369. *
  370. * RETURNS:
  371. *
  372. * int            -- Error value (0 = no error)
  373. *
  374. * NOTES:
  375. * This should be implemented by descendents
  376. */
  377.  
  378. int CSK_Socket::getpeername(void *, int *)
  379. {
  380.     UNIMPLEMENTED;
  381.     return EOPNOTSUPP;
  382. }
  383.  
  384.  
  385. /*************************************************************************** *
  386. * FUNCTION:
  387. *
  388. * CSK_Socket::getsockopt
  389. *
  390. * DESCRIPTION:
  391. *
  392. * Get socket options for this socket
  393. *
  394. * PARAMETERS:
  395. *
  396. * int            -- unused
  397. * int            -- unused
  398. * void *        -- unused
  399. * int *            -- unused
  400. *
  401. * RETURNS:
  402. *
  403. * int            -- Error value (0 = no error)
  404. *
  405. * NOTES:
  406. * This should be implemented by descendents
  407. */
  408.  
  409. int CSK_Socket::getsockopt(int, int, void *, int *)
  410. {
  411.     UNIMPLEMENTED;
  412.     return EOPNOTSUPP;
  413. }
  414.  
  415. /*************************************************************************** *
  416. * FUNCTION:
  417. *
  418. * CSK_Socket::setsockopt
  419. *
  420. * DESCRIPTION:
  421. *
  422. * Set socket options for this socket
  423. *
  424. * PARAMETERS:
  425. *
  426. * int            -- unused
  427. * int            -- unused
  428. * void *        -- unused
  429. * int            -- unused
  430. *
  431. * RETURNS:
  432. *
  433. * int            -- Error value (0 = no error)
  434. *
  435. * NOTES:
  436. * This should be implemented by descendents
  437. */
  438.  
  439. int CSK_Socket::setsockopt(int, int, void *, int)
  440. {
  441.     UNIMPLEMENTED;
  442.     return EOPNOTSUPP;
  443. }
  444.  
  445.  
  446. /*************************************************************************** *
  447. * FUNCTION:
  448. *
  449. * CSK_Socket::fcntl
  450. *
  451. * DESCRIPTION:
  452. *
  453. * Perform a flag control action on this socket
  454. *
  455. * PARAMETERS:
  456. *
  457. * unsigned int    -- unused
  458. * int            -- unused
  459. *
  460. * RETURNS:
  461. *
  462. * int            -- Error value (0 = no error)
  463. *
  464. * NOTES:
  465. * This should be implemented by descendents
  466. */
  467.  
  468. int CSK_Socket::fcntl(unsigned int, int)
  469. {
  470.     UNIMPLEMENTED;
  471.     return EOPNOTSUPP;
  472. }
  473.  
  474.  
  475. /*************************************************************************** *
  476. * FUNCTION:
  477. *
  478. * CSK_Socket::ioctl
  479. *
  480. * DESCRIPTION:
  481. *
  482. * Perform an I/O control action on this socket
  483. *
  484. * PARAMETERS:
  485. *
  486. * unsigned int    -- unused
  487. * void *        -- unused
  488. *
  489. * RETURNS:
  490. *
  491. * int            -- Error value (0 = no error)
  492. *
  493. * NOTES:
  494. * This should be implemented by descendents
  495. */
  496.  
  497. int CSK_Socket::ioctl(unsigned int, void *)
  498. {
  499.     UNIMPLEMENTED;
  500.     return EOPNOTSUPP;
  501. }
  502.  
  503.  
  504. /*************************************************************************** *
  505. * FUNCTION:
  506. *
  507. * CSK_Socket::fstat
  508. *
  509. * DESCRIPTION:
  510. *
  511. * Get the file status for this socket
  512. *
  513. * PARAMETERS:
  514. *
  515. * struct stat *        -- Pointer to buffer for return values
  516. *
  517. * RETURNS:
  518. *
  519. * int                -- Error value (0 = no error)
  520. *
  521. */
  522.  
  523. int CSK_Socket::fstat(struct stat * buf)
  524. {
  525.     buf->st_dev            =    0;
  526.     buf->st_ino            =    0;
  527.     buf->st_mode        =    S_IFSOCK | 0666 ;
  528.     buf->st_nlink        =    1;
  529.     buf->st_uid            =    0;
  530.     buf->st_gid            =    0;
  531.     buf->st_rdev        =    0;
  532.     buf->st_size        =    1;
  533.     buf->st_atime        =    time(NULL);
  534.     buf->st_mtime        =    time(NULL);
  535.     buf->st_ctime        =    time(NULL);
  536.     buf->st_blksize        =    1;
  537.     buf->st_blocks        =    1;
  538.     
  539.     return 0;
  540. }
  541.  
  542.  
  543. /*************************************************************************** *
  544. * FUNCTION:
  545. *
  546. * CSK_Socket::lseek
  547. *
  548. * DESCRIPTION:
  549. *
  550. * Move the read position on this socket to the given location
  551. *
  552. * PARAMETERS:
  553. *
  554. * long            -- unused
  555. * int            -- unused
  556. *
  557. * RETURNS:
  558. *
  559. * int            -- Error value (0 = no error)
  560. *
  561. * NOTES:
  562. * This should be implemented by descendents
  563. */
  564.  
  565. long CSK_Socket::lseek(long, int)
  566. {
  567.     UNIMPLEMENTED;
  568.     return EOPNOTSUPP;
  569. }
  570.  
  571.  
  572. /*************************************************************************** *
  573. * FUNCTION:
  574. *
  575. * CSK_Socket::ftruncate
  576. *
  577. * DESCRIPTION:
  578. *
  579. * ???
  580. *
  581. * PARAMETERS:
  582. *
  583. * long            -- unused
  584. *
  585. * RETURNS:
  586. *
  587. * int            -- Error value (0 = no error)
  588. *
  589. * NOTES:
  590. * This should be implemented by descendents
  591. */
  592.  
  593. int CSK_Socket::ftruncate(long)
  594. {
  595.     UNIMPLEMENTED;
  596.     return EOPNOTSUPP;
  597. }
  598.  
  599.  
  600. /*************************************************************************** *
  601. * FUNCTION:
  602. *
  603. * CSK_Socket::isatty
  604. *
  605. * DESCRIPTION:
  606. *
  607. * Check whether this socket is a tty (real or virtual terminal)
  608. *
  609. * RETURNS:
  610. *
  611. * int            -- Error value (0 = no error)
  612. *
  613. * NOTES:
  614. * This should be implemented by descendents
  615. */
  616.  
  617. int CSK_Socket::isatty()
  618. {
  619.     return 0;
  620. }
  621.  
  622.  
  623. /*************************************************************************** *
  624. * FUNCTION:
  625. *
  626. * CSK_Socket::shutdown
  627. *
  628. * DESCRIPTION:
  629. *
  630. * Shutdown some or all of this socket
  631. *
  632. * PARAMETERS:
  633. *
  634. * int            -- unused
  635. *
  636. * RETURNS:
  637. *
  638. * int            -- Error value (0 = no error)
  639. *
  640. * NOTES:
  641. * This should be implemented by descendents
  642. */
  643.  
  644. int CSK_Socket::shutdown(int)
  645. {
  646.     UNIMPLEMENTED;
  647.     return EOPNOTSUPP;
  648. }
  649.  
  650.  
  651. /*************************************************************************** *
  652. * FUNCTION:
  653. *
  654. * CSK_Socket::pre_select
  655. *
  656. * DESCRIPTION:
  657. *
  658. * ???
  659. *
  660. * PARAMETERS:
  661. *
  662. * Boolean *        -- Pointer to memory for return value : can read
  663. * Boolean *        -- Pointer to memory for return value : read write
  664. * Boolean *        -- Pointer to memory for return value : exception ???
  665. *
  666. */
  667.  
  668. void CSK_Socket::pre_select(Boolean, Boolean, Boolean)
  669. {
  670. }
  671.  
  672. /*************************************************************************** *
  673. * FUNCTION:
  674. *
  675. * CSK_Socket::select
  676. *
  677. * DESCRIPTION:
  678. *
  679. * Move the read position on this socket to the given location
  680. *
  681. * PARAMETERS:
  682. *
  683. * Boolean *        -- Pointer to memory for return value : can read
  684. * Boolean *        -- Pointer to memory for return value : read write
  685. * Boolean *        -- Pointer to memory for return value : exception ???
  686. *
  687. * RETURNS:
  688. *
  689. * int            -- Error value (0 = no error)
  690. * Flags for can-read, can-write, and exception are returned in the
  691. * given memory.
  692. *
  693. * NOTES:
  694. * This should be implemented by descendents
  695. */
  696.  
  697. int CSK_Socket::select(Boolean * canRead, Boolean * canWrite, Boolean * exception)
  698. {
  699.     if (canRead)
  700.         *canRead = false;
  701.     
  702.     if (canWrite)
  703.         *canWrite =    false;
  704.     
  705.     if (exception)
  706.         *exception = false;
  707.     
  708.     return 0;
  709. }
  710.  
  711.  
  712. /*************************************************************************** *
  713. * FUNCTION:
  714. *
  715. * CSK_Socket::post_select
  716. *
  717. * DESCRIPTION:
  718. *
  719. * ???
  720. *
  721. * PARAMETERS:
  722. *
  723. * Boolean *        -- Pointer to memory for return value : can read
  724. * Boolean *        -- Pointer to memory for return value : read write
  725. * Boolean *        -- Pointer to memory for return value : exception ???
  726. *
  727. */
  728.  
  729. void CSK_Socket::post_select(Boolean, Boolean, Boolean)
  730. {
  731. }
  732.  
  733. /* end of SK_Socket.cc */
  734.  
  735.